package com.alongstudio.account.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.alongstudio.account.commons.exception.BusinessException;
import com.alongstudio.account.entity.Project;
import com.alongstudio.account.service.IProjectService;

@Service(value = "ProjectService")
public class ProjectService extends BaseService implements IProjectService {
	private String className = ProjectService.class.getName();

	@Override
	public String createProject(Project project) throws BusinessException {
		try {
			dao.create(project);
		}
		catch (Exception e) {
			throw new BusinessException(className, e);
		}

		return project.getId();
	}

	@Override
	public List<Project> findAllProject(String userId) throws BusinessException {
		List<Project> list = null;
//		try {
//			list = dao.query("from Project p where p.clientUser.id=" + userId);
//		}
//		catch (Exception e) {
//			throw new BusinessException(className, e);
//		}
		return list;
	}

	@Override
	public boolean updateProject(Project project) throws BusinessException {
		try {
			dao.update(project);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException(className, e);
		}
	}

	@Override
	public boolean deleteProject(String id) throws BusinessException {
		try {
			dao.deleteByPk(Project.class, id);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException(className, e);
		}
	}
}
